﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text;


namespace A_Modules.FileMD5
{
    class FileMD5
    {
        MD5 _md5 =  new MD5CryptoServiceProvider();
        public bool Test()
        {
            FileStream fs =null;
            FileStream fs1 = null;
           
            try
            {

                fs =
                    File.OpenRead(@"D:\DevProjects\Myprojects\DotNet\iceternally-dotnet-test\trunk\BaseLab\BaseLab20\A-Modules\FileMD5\TestFile.txt");

                if (!File.Exists(@"D:\DevProjects\Myprojects\DotNet\iceternally-dotnet-test\trunk\BaseLab\BaseLab20\A-Modules\FileMD5\TestFile1.txt"))
                    return false;

                fs1 =
                    File.OpenRead(@"D:\DevProjects\Myprojects\DotNet\iceternally-dotnet-test\trunk\BaseLab\BaseLab20\A-Modules\FileMD5\TestFile1.txt");


                //return _md5.ComputeHash(fs) == _md5.ComputeHash(fs1);

                Convert.ToBase64String(_md5.ComputeHash(fs));

                return this.bytesEquals(_md5.ComputeHash(fs), _md5.ComputeHash(fs1));

                Guid df = new Guid(_md5.Hash);
            }
            catch (Exception)
            {
                
                throw;
            }
            finally
            {
             if(fs!=null)
                 fs.Close();
             if (fs1 != null)
                 fs1.Close();
            }
        }

        private bool bytesEquals(byte[] b1,byte[] b2)
        {
            if(b1.Length != b2.Length)
                return false;

            for (int i = 0; i < b2.Length; i++)
            {
                if (b1[i] != b2[i])
                    return false;
            }
            return true;
        }

        //public static bool bytesEquale( byte[] this aa)
        //{
        //    return true;
        //}
    }
}
